﻿
Imports std
Imports centrosphere

Partial Public MustInherit Class storageJobDistributor
    Inherits distributor
    Protected Shared Function storageJob(ByVal ijob As ijob) As storageJob
        Return convertor.cast(Of storageJob)(ijob)
    End Function

    Protected Shared Function storageJob(ByVal targetJob As indexedJob) As storageJob
        assert(Not targetJob Is Nothing)
        Return storageJob(targetJob.job())
    End Function

    Protected Class storageJob_distribute_switcher
        Inherits distribute_switcher(Of Byte)

        Public Sub New(ByVal default_action As distribute_delegate,
                       ByVal ParamArray selectors() As condition_action)
            MyBase.New(default_action, selectors)
        End Sub

        Public Sub New(ByVal ParamArray selectors() As condition_action)
            MyBase.New(selectors)
        End Sub

        Public Shadows Function execute(ByVal inputJob As ijob,
                                        ByVal targetJobs As vector(Of pair(Of UInt32, ijob))) As Boolean
            Return MyBase.execute(storageJob(inputJob).command, inputJob, targetJobs)
        End Function
    End Class

    Protected Class storageJob_aggregate_switcher
        Inherits aggregate_switcher(Of Byte)

        Public Sub New(ByVal default_action As aggregate_delegate,
                       ByVal ParamArray selectors() As condition_action)
            MyBase.New(default_action, selectors)
        End Sub

        Public Sub New(ByVal ParamArray selectors() As condition_action)
            MyBase.New(selectors)
        End Sub

        Public Shadows Function execute(ByVal targetJobs() As indexedJob,
                                        ByVal inputJob As ijob) As Boolean
            Return MyBase.execute(storageJob(inputJob).command, targetJobs, inputJob)
        End Function
    End Class
End Class
